package soup;

import java.io.FileInputStream;
import java.io.IOException;

import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;

import static org.lwjgl.opengl.GL11.*;

public class Main {
	public static void main(String args[]) {
		
		//Set up OpenGL stuff:
		try {
			Display.setDisplayMode(new DisplayMode(800,600));
			Display.create();
			Display.setVSyncEnabled(true);
		} catch(LWJGLException e) {
			e.printStackTrace();
			System.exit(1);
		}
		
		//enable textures (for sprites)
		glEnable(GL_TEXTURE_2D);
		//clear to black when we call glClear(...)
		glClearColor(0,0,0,0);
		//enable alpha blending
		glEnable(GL_BLEND);
		//use an alpha blend function best with primitives drawn from farthest to nearest
		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
		//disable depth testing, 'cause it's all 2D right now
		glDisable(GL_DEPTH_TEST);
		
		//set up an orthographic projection:
		glMatrixMode(GL_PROJECTION);
		glLoadIdentity();
		glOrtho(0, 800, 600, 0, 1, -1);
		
		//set our viewport:
		glMatrixMode(GL_MODELVIEW);
		glLoadIdentity();
		glViewport(0, 0, 800, 600);
		
		//Load the sprite:
		Sprite arrow = null;
		Sprite background = null;
		try {
			arrow = new Sprite("PNG", new FileInputStream("data/arrow.png"));
			background = new Sprite("PNG", new FileInputStream("data/concrete800_600.png"));
		} catch(IOException e) {
			e.printStackTrace();
			System.exit(1);
		}
		
		float angle = 0;
		while(!Display.isCloseRequested()) {
			glClear(GL_COLOR_BUFFER_BIT);
			background.render(400,300); //coordinate are center of image!
			arrow.render(400,300,angle);
			Display.update();
			Display.sync(60); //try to maintain 60 fps
			angle += 1;
		}
		
	}
}
